/**
 * 
 */
package evolution;

import ca.swank.hardquor.Move;
import ca.swank.hq.ai.CachingSmartBoard;

/**
 * @author Alon Segal
 * 
 */
public class LastStateFitnessCalculator extends FitnessCalculator {

	/**
	 * 
	 */
	public LastStateFitnessCalculator(BoardEvaluator be) {
		super(be);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see evolution.FitnessCalculator#getFitness(evolution.Individual)
	 */
	@Override
	public double getFitness(Individual in) {
		BoardEvaluator bfe = new BFSBoardEvaluator();
		
		Move[] moveSeq = in.getMoveSeq();
		
		CachingSmartBoard board = (CachingSmartBoard)in.getInitialBoard().clone();
		for(int i=0; i < moveSeq.length; i++) {
			board.makeMove(moveSeq[i]);
		}

		return bfe.evalBoard(board, in.getTurn());
	}

}
